package zuoye_3_24;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Random;

public class Zuoye_3 {
	public static void main(String[] args) throws IOException {
		ArrayList<Student> list = new ArrayList<>();
		BufferedReader r = new BufferedReader(new FileReader("names1.txt"));
		String line;
		while((line = r.readLine())!=null) {
			String arr[] = line.split("-");
			Student stu = new Student(arr[0],arr[1],Integer.parseInt(arr[2]),Double.parseDouble(arr[3]));
			list.add(stu);
		}
		dianming3(list);
	}

	private static void dianming3(ArrayList<Student> list) throws IOException {
		// TODO Auto-generated method stub
		BufferedWriter w = new BufferedWriter(new FileWriter("names1.txt"));
		Random random = new Random();
		if(((Student)list.get(random.nextInt(list.size()))).getWeight()==3.0) {
			System.out.println("张三-男-23");
			for (Student student : list) {
				String str = student.getName()+"-"+student.getGender()+"-"+student.getAge()+"-"+"1";
				w.write(str);
				w.newLine();
			}
			w.close();
		}else {
			String s = list.get(random.nextInt(list.size())).toString1();
			System.out.println(s);
			for (Student student : list) {
				String str = student.getName()+"-"+student.getGender()+"-"+student.getAge()+"-"+((int)student.getWeight()+1);
				w.write(str);
				w.newLine();
			}
			w.close();
		}
	}
}

